using Gtk;
using System;
using System.Data;
using System.Globalization;
using System.Reflection;

using Serpis;
using PArticulo;


public partial class MainWindow : Gtk.Window
{
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		
		refreshActions();
		
		notebook.SwitchPage += delegate {
			refreshActions();
		};
		
		notebook.PageRemoved += delegate {
			refreshActions();
		};
		
		articuloAction.Activated += delegate {
			ArticuloListView articuloListView = new ArticuloListView();
			
			notebook.AddTab(articuloListView);
			
			articuloListView.Changed += delegate {
				refreshActions();
			};
		};
		
		categoriaAction.Activated += delegate {
			CategoriaListView categoriaListView= new CategoriaListView();
			
			notebook.AddTab(categoriaListView);
			
			categoriaListView.Changed += delegate {
				refreshActions();
			};
		};
		
		findAction.Activated += delegate {
			currentListView.Refresh();
		};
		
		newAction.Activated += delegate {
			currentListView.New();
		};
		
		editAction.Activated += delegate {
			currentListView.Edit();
		};
		
		deleteAction.Activated += delegate {
			currentListView.Delete();
		};
	}
	
	private void refreshActions() {
		IListView listView= currentListView;
		newAction.Sensitive= listView != null;
		editAction.Sensitive= listView != null && listView.HasSelected;
		deleteAction.Sensitive= listView != null && listView.HasSelected;
		findAction.Sensitive= listView != null;
	}
	
	private IListView currentListView {
		get {return notebook.CurrentPageWidget as IListView;}
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}